﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Bigger.Web.Mvc;
using Bigger.Framework;

namespace CJAtech.BBS.Web.Controllers
{
    public class BaseController : BiggerController
    {
        protected bool IsRelease
        {
            get
            {
                return ConfigHelper.GetBoolValue("IsRelease", true);
            }
        }
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (IsRelease)
            {
                if (Request.UserAgent.IsNull() || !Request.UserAgent.Contains("MicroMessenger"))
                {
                    if (Request.IsAjaxRequest())
                    {
                        filterContext.Result = new JsonResult
                        {
                            Data = new InvokeResult { ResultCode = "BrowserNotAllowed", ResultMessage = "请使用微信浏览器访问" },
                            JsonRequestBehavior = JsonRequestBehavior.AllowGet
                        };
                    }
                    else
                    {
                        filterContext.Result = new ContentResult
                        {
                            Content = "请使用微信浏览器访问"
                        };
                    }
                }
            }
        }
    }
}
